<?php

namespace App\Service;

use App\Model\t_lvyou;
use App\Utility\Express;
use EasySwoole\EasySwoole\Logger;

class IndexService extends BaseService
{
    public function lvy()
    {
        $names = t_lvyou::create()->all();

        foreach ($names as $name) {
            $res = Express::getInstance()->lvy($name['name']);
            Logger::getInstance()->info(json_encode($res));
            if ($res['resp']['RespCode'] == 200) {
                $data = $res['data']['record'][0];
                $par = [
                    'address' => $data['addr'],
                    'lat' => $data['lat'],
                    'lng' => $data['lng'],
                    'zhtjg' => $data['type'],
                    'xfx' => '否',
                    'info' => $data['spot'],
                    'jctj' => $data['opentime']
                ];

                $r = t_lvyou::create()->update($par, ['name' => $name['name']]);
            }
        }

        return [
            'result' => true,
            'msg' => 'success',
            'data' => 'success'
        ];
    }
}